package com.jinzecloud.reportapproval.controller;

import com.jinzecloud.reportapproval.constant.AdminSwaggerTagConst;
import com.jinzecloud.reportapproval.form.RoleUserQueryForm;
import com.jinzecloud.reportapproval.form.RoleUserUpdateForm;
import com.jinzecloud.reportapproval.service.RoleUserService;
import com.jinzecloud.reportapproval.utils.R;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 角色的员工
 */
@RestController
@CrossOrigin
@Api(tags = AdminSwaggerTagConst.System.SYSTEM_ROLE_EMPLOYEE)
public class RoleUserController {

    @Resource
    private RoleUserService roleUserService;

    @Operation(summary = "查询某个角色下的用户列表")
    @PostMapping("/role/user/queryUser")
    public R queryUser(@RequestBody RoleUserQueryForm roleUserQueryForm) {
        return roleUserService.queryUser(roleUserQueryForm);
    }


    @Operation(summary = "从角色成员列表中移除用户")
    @GetMapping("/role/employee/removeUser")
//    @SaCheckPermission("system:role:employee:delete")
    public R removeUser(Long userId, Long roleId) {
        return roleUserService.removeRoleUser(userId, roleId);
    }

    @Operation(summary = "从角色成员列表中批量移除用户")
    @PostMapping("/role/employee/batchRemoveRoleEmployee")
//    @SaCheckPermission("system:role:employee:batch:delete")
    public R batchRemoveUser(@Valid @RequestBody RoleUserUpdateForm updateForm) {
        return roleUserService.batchRemoveRoleUser(updateForm);
    }

    @Operation(summary = "角色成员列表中批量添加用户")
    @PostMapping("/role/employee/batchAddRoleEmployee")
//    @SaCheckPermission("system:role:employee:add")
    public R addUserList(@Valid @RequestBody RoleUserUpdateForm addForm) {
        return roleUserService.batchAddRoleUser(addForm);
    }

    @Operation(summary = "获取用户所有选中的角色和所有角色")
    @GetMapping("/role/employee/getRoles/{userId}")
    public R getRoleByUserId(@PathVariable Long userId) {
        return R.ok().put("data", roleUserService.getRoleInfoListByUserId(userId));
    }
}
